package de.uni.muenster.idw2.data;

import java.util.ArrayList;
import java.util.Arrays;


public class Edge implements Comparable<Edge>{
	String name;
	//Vertex vertex1, vertex2;
	Vertex vertices[];
	

	public void setVertices(Vertex[] vertices) {
		this.vertices = vertices;
	}
	
	
	public Edge(String name, Vertex vertices[]){
		this.name = name;
		this.vertices = vertices;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

//	public Vertex getVertex1() {
//		return vertex1;
//	}

//	public void setVertex1(Vertex vertex1) {
//		this.vertex1 = vertex1;
//	}

//	public Vertex getVertex2() {
//		return vertex2;
//	}

//	public void setVertex2(Vertex vertex2) {
//		this.vertex2 = vertex2;
//	}
	
//	public void setVertices(Vertex vertex1, Vertex vertex2){
//		setVertex1(vertex1);
//		setVertex2(vertex2);
//	}
	public Vertex[] getVertices(){
		//TODO: implement with proper deep copy?
		return new Vertex[] {vertices[0], vertices[1]};
	}

	@Override
	public int compareTo(Edge edge1) {
		// TODO Auto-generated method stub
		Vertex[] v1= edge1.getVertices();
		if(v1[0]== vertices[0] && v1[1]==vertices[2])
			return 0;
		else if(v1[0]== vertices[0] || v1[1]==vertices[2])
			return 1;
		else
			return -1;
	}
	
	public Vertex getOtherVertex(Vertex vertex1){
		if(vertex1.getName().equals(vertices[0].getName())){
			return vertices[1];
		}
		else if(vertex1.getName().equals(vertices[1].getName())){
			return vertices[0];
		}
		else{
			return null;
		}
	}
	
	public boolean hasVertex(Vertex vertex1){
		if (vertex1 == null) return false;
		if (vertices[0]==null || vertices[1]==null) return false;
		return ((vertex1.getCoord().getX()==vertices[0].getCoord().getX() && 
				vertex1.getCoord().getY()==vertices[0].getCoord().getY() &&
				vertex1.getCoord().getFloor()==vertices[0].getCoord().getFloor() )||
				(vertex1.getCoord().getX()==vertices[1].getCoord().getX() && 
				vertex1.getCoord().getY()==vertices[1].getCoord().getY() &&
				vertex1.getCoord().getFloor()==vertices[1].getCoord().getFloor() )
				);

	}
	
}
